package bar.dark.lee.setting.sms.smsinsert;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import bar.dark.lee.BDConstents;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.setting.sms.InputData;

public class SmsInMoney2 
{
	private int smsType; 
//	private boolean flagATM = false;
//	private boolean flagHalbu = false;
//	private String halbuMonth = "0";
//	
//	private boolean FLAG = true;
	private boolean available = false;
//	
//	private boolean outmoneyFlag = false;
//	
//	//1:check 2:credit
	private int checkcreditFlag = 0;
//	
	private final int CHECK = 1;
	private final int CREDIT = 2;
//	
	private String message;
	private InputData data;
//	
	private String date;
	
	public SmsInMoney2(){};
	
	public SmsInMoney2(InputData data, String message, String date, int smsType, int checkcreditFlag)
	{
		this.data = data;
		this.message = message;
		this.date = date;
		this.smsType = smsType;
		this.checkcreditFlag = checkcreditFlag;
		
		inMoney();
	}
	
	public boolean getAvailable()
	{
		return available;
	}
	
	public InputData getData()
	{
		return data;
	}
	
	public int getSmsType()
	{
		return smsType;
	}
	
	//TODO
	private void inMoney()
	{
		if ( (data.getName().equalsIgnoreCase("동부증권") ) )
		{
			/*
			 * [동부증권]이승구(100149***01)님 이승구님께서 750,000원 이체입금
			 */
			
			Pattern pName = Pattern.compile("\\((.+)\\)님");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\s+(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//				Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//				Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("님\\s+(.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("동부증권" + "(" + mName.group(1).replaceAll("\\*", "").substring(0, 4) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//				if (mDate.find()) 
//				{
//					for (int i=0; i<mDate.groupCount(); i++) 
//					{
//						data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//					}
//					
//					available = true;
//				}
//				else
//				{
//					originalParsing();
//				}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().indexOf("동양") != -1) )
		{
			/*[동양]07/18 09:34 706-71-03***6입금250,000잔액63,583 --- 그냥입금
				
				[동양]07/19 14:18 706-71-03***6입금270,000기업/이원준 잔액1,927,239 --- 이체
				
			 * [동양]채권이자 703-71-01***6동양254채권120,980원 입금
			 * 
			 * [동양]01/22 05:59 85**-**11-702*입금80,000기업/한우값 잔액16,102,243
			 * 
			 * [동양]03/28 10:43 096-01-01***8입금100,000CMS자동입금 잔액100,004
			 */
			//Pattern pName = Pattern.compile("\\d{2}:\\d{2}\\s+(.{4})");
//				Pattern pName = Pattern.compile("(\\d{2,}-\\d{2,})-\\d{1,}");
//				Matcher mName = pName.matcher(message);
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+)입금\\d");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile("채권이자\\s+(.+)동양");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("입금(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pMoney2 = Pattern.compile("채권(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney2 = pMoney2.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("입금\\d*,*\\d*,*\\d*,*\\d(.+)\\s+잔액");	// 이체
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("입금\\d*,*\\d*,*\\d*,*\\d잔액");	// atm인듯
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo3 = Pattern.compile("채권\\d*,*\\d*,*\\d*,*\\d원\\s+입금");
			Matcher mMemo3 = pMemo3.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName.group(1).replace("-", "") + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + mName2.group(1).replace("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else if (mMoney2.find()) 
			{
				for (int i=0; i<mMoney2.groupCount(); i++) 
				{
					data.setMoney((mMoney2.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo2.find()) 
			{
				data.setMemo1("현금 입금");
				data.setMemo2("현금 입금");
				data.setMemo3("현금 입금");
				data.setMemo4("현금 입금");
				
				smsType = BDConstents.IN_ATM_SMS;
			}
			else if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo3.find()) 
			{
				data.setMemo1("채권이자");
				data.setMemo2("채권이자");
				data.setMemo3("채권이자");
				data.setMemo4("채권이자");
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("농협"))
		{
			/*
			 * 농협 2012/08/26 741011-56-129*** 100,000원(윤은희)입금.잔액558,238원
			 * 
			 * 농협 321-12-314*** 449,730원(충북도교육청)17일 자동입금처리.잔액 2,471,181원

				농협 302-0534-6948-** 100,000원(정원찬)25일 자동입금처리.잔액 164,039원
				
				농협 169-02-788*** 5,705,560원(삼성물산)21일 자동입금처리.잔액-7,755,109원
				
				
				농협 2012/09/03 643-12-095*** 50,000원( 042-5003)입금.잔액499,053원 	// atm기 현금 입금
				
				농협 2013/01/14 302-0475-6662-** 482,650원(현대73028134)입금.잔액2,257,370원


				농협)10:33 xx님이 xxx님의 농협계좌로 xx,xxx원 입금함
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}-\\d{1,}-\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pName2 = Pattern.compile(".+님이\\s+(.+)님의\\s+.+계좌로");
			Matcher mName2 = pName2.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{4}/\\d{2}/\\d{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pDate2 = Pattern.compile("\\)(\\d{1,2})일");
			Matcher mDate2 = pDate2.matcher(message);
			Pattern pMemo = Pattern.compile("\\d원\\s*\\((.+\\s*.+)\\)입금");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d원\\s*\\((.+)\\)");
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo4 = Pattern.compile(":\\d{1,2}\\s+(.+님이\\s+.+님의\\s+.+계좌로\\s+\\d*,*\\d*,*\\d*,*\\d원)");
			Matcher mMemo4 = pMemo4.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)).replaceAll("-", "") + ")");
				}
			}
			else if (mName2.find())
			{
				for (int i=0; i<mName2.groupCount(); i++) 
				{
					data.setName("농협(" + mName2.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (mDate2.find()) 
			{
				for (int i=0; i<mDate2.groupCount(); i++) 
				{
					if (date != null && date.length() > 0)
					{
						data.setDate(date.substring(0, 6) + mDate2.group(1));
					}
					else
					{
						data.setDate( (BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH))).substring(0, 6) + mDate2.group(1) );
					}
				}
			}
			else if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(mDate.group(1).replaceAll("/", ""));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
				//originalParsing();
			}
			
			if (mMemo.find()) 
			{
				Pattern pMemo3 = Pattern.compile("\\d{3}-\\d{4}");
				Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
				
				if (mMemo3.find())
				{
					data.setMemo1("현금 입금");
					data.setMemo2("현금 입금");
					data.setMemo3("현금 입금");
					data.setMemo4("현금 입금");
					
					smsType = BDConstents.IN_ATM_SMS;
				}
				else
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else if (mMemo4.find()) 
			{
				for (int i=0; i<mMemo4.groupCount(); i++) 
				{
					data.setMemo1((mMemo4.group(1)));
					data.setMemo2((mMemo4.group(1)));
					data.setMemo3((mMemo4.group(1)));
					data.setMemo4((mMemo4.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("KDB") ) )
		{
			/*
				(KDB)020****3325
				입금
				180,000원
				홍길동
				잔액217,750원 16:47
				
				(KDB)홍길동님
				020****4137
				입금
				1,568,693원
				Xxxxx(주)
				03:18
			 */
			
			Pattern pName = Pattern.compile("(\\d{1,}\\*{1,}\\d{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//				Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//				Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s?.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+\\d{1,2}:\\d{1,2}");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("KDB" + "(" + mName.group(1) + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//				if (mDate.find()) 
//				{
//					for (int i=0; i<mDate.groupCount(); i++) 
//					{
//						data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//					}
//					
//					available = true;
//				}
//				else 
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("대우증권") ) )
		{
			/*
				[대우증권]08/30[18:40],210-20-114**** 입금100,000잔액100,000
			 */
			
			Pattern pName = Pattern.compile(",(.{1,8}-.{1,8}-.{1,8})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s*(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
//				Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//				Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s?.+)\\s+잔액");
//				Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("대우증권" + "(" + mName.group(1).replaceAll("-", "") + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//				if (mDate.find()) 
//				{
//					for (int i=0; i<mDate.groupCount(); i++) 
//					{
//						data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//					}
//					
//					available = true;
//				}
//				else
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//				if (mMemo.find()) 
//				{
//					for (int i=0; i<mMemo.groupCount(); i++) 
//					{
					data.setMemo1("내용 없음");
					data.setMemo2("내용 없음");
					data.setMemo3("내용 없음");
					data.setMemo4("내용 없음");
//					}
//				}
//				else
//				{
//					originalParsing();
//				}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("수협알림") ) )
		{
			/*
				[수협알림]
				홍길동님
				[05501049***]
				제이드입금
				75,000원
			 */
			
			Pattern pName = Pattern.compile("(\\d{1,}\\*{1,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//				Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
//				Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\*\\]\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("수협" + "(" + mName.group(1).replaceAll("\\*", "") + ")" );
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
//				if (mDate.find()) 
//				{
//					for (int i=0; i<mDate.groupCount(); i++) 
//					{
//						data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
//					}
//					
//					available = true;
//				}
//				else 
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("기타매체로") || data.getName().equalsIgnoreCase("CD/ATM으로") || data.getName().equalsIgnoreCase("인터넷으로") || data.getName().equalsIgnoreCase("스마트로"))
		{
			/*
			 * 
			 * CD/ATM으로 123,123원 입급, 잔액 : 123,123(06513**77547)17:58:15	// 입금인지 입금인지 모르겠따 둘다할것
			 * 
			 * 인터넷으로 (재)한빛님께서 250,000원 입금, 잔액 : 250,000(50810*11106)15:15:45
			 * 
			 * 스마트로 김미정(생활비)님께서 12,500원 입금, 잔액 : 735,904(50810*11106)12:48:09
			 */
			Pattern pName = Pattern.compile("잔액\\s+:\\s+-*\\d*,*\\d*,*\\d*,*\\d\\((.+)\\)\\d{2}:\\d{2}:\\d{2}");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("\\W+(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
//				Pattern pDate = Pattern.compile("\\d{4}/(\\d{2}/\\d{2})");
//				Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("기타매체로\\s+(.+)님께서");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("인터넷으로\\s+(.+)님께서");
			Matcher mMemo2 = pMemo2.matcher(message);
			Pattern pMemo5 = Pattern.compile("스마트로\\s+(.+)님께서");
			Matcher mMemo5 = pMemo5.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("대구" + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1((mMemo2.group(1)));
					data.setMemo2((mMemo2.group(1)));
					data.setMemo3((mMemo2.group(1)));
					data.setMemo4((mMemo2.group(1)));
				}
			}
			else if (mMemo5.find()) 
			{
				for (int i=0; i<mMemo5.groupCount(); i++) 
				{
					data.setMemo1((mMemo5.group(1)));
					data.setMemo2((mMemo5.group(1)));
					data.setMemo3((mMemo5.group(1)));
					data.setMemo4((mMemo5.group(1)));
				}
			}
			else
			{
				Pattern pMemo3 = Pattern.compile("CD/ATM");
				Matcher mMemo3 = pMemo3.matcher(message);
				
				if (mMemo3.find())
				{
					data.setMemo1("현금 입금");
					data.setMemo2("현금 입금");
					data.setMemo3("현금 입금");
					data.setMemo4("현금 입금");
					
					smsType = BDConstents.IN_ATM_SMS;
				}
				else
				{
					available = false;
					return;
				}
			}
			
			available = true;
		}
		else if (data.getName().equalsIgnoreCase("HMC 투자"))
		{
			/*
			 * [HMC 투자]
				15192***-11
				12/09/25 03:50
				전자금융급여
				1,950,434원
				외환 급여
			 */
			Pattern pName = Pattern.compile("(\\d{2,}-\\d{1,})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{2}/\\d{2}/\\d{2})");
			Matcher mDate = pDate.matcher(message);
			//Pattern pMemo = Pattern.compile("\\d{2}:\\d{2}\\s+(.+\\s*.+)\\s+\\d*,*\\d*,*\\d*,*\\d원");
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)).replaceAll("-", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate("20" + mDate.group(1).replaceAll("/", ""));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("우체국")) )
		{
			/*
			 * 우체국,14:00
				603********601
				입금30,000원
				잔액6,875원
				현대카드				// 그냥 입금
				
				우체국,21:18
				613********601
				입금90,000원
				잔액103,925원
				ATM출금
			 */
			
			Pattern pName = Pattern.compile("(\\d{2,}\\*{3,}\\d{2,})\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액-*\\d*,*\\d*,*\\d*,*\\d원(.+$)");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("우체국" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					Pattern pMemo3 = Pattern.compile("ATM입금");
					Matcher mMemo3 = pMemo3.matcher(mMemo.group(1));
					
					if (mMemo3.find())
					{
						data.setMemo1("현금 입금");
						data.setMemo2("현금 입금");
						data.setMemo3("현금 입금");
						data.setMemo4("현금 입금");
						
						smsType = BDConstents.IN_ATM_SMS;
					}
					else
					{
						data.setMemo1((mMemo.group(1)));
						data.setMemo2((mMemo.group(1)));
						data.setMemo3((mMemo.group(1)));
						data.setMemo4((mMemo.group(1)));
					}
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( data.getName().equalsIgnoreCase("기업") )
		{
			/*
			 * 01/23 20:31
				입금 14,000원
				타누키돈부리
				020***86302019
				기업
			 */
			Pattern pName = Pattern.compile("(\\d{2,}\\*\\*\\*\\d{3,})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("([\\d]{2}[/][\\d]{2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+\\d");
			Matcher mMemo = pMemo.matcher(message);
			Pattern pMemo2 = Pattern.compile("입금\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+)\\s+\\d");
			Matcher mMemo2 = pMemo2.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else if (mMemo2.find()) 
			{
				for (int i=0; i<mMemo2.groupCount(); i++) 
				{
					data.setMemo1(mMemo2.group(1));
					data.setMemo2(mMemo2.group(1));
					data.setMemo3(mMemo2.group(1));
					data.setMemo4(mMemo2.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("신협")) )
		{
			/*
			 * 신협)132-***-*91246 11/27 06:26 입금 81,055원 BC779258872    잔액2,059,986원
			 */
			Pattern pName = Pattern.compile("신협\\)(.{12,17})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("\\d*,*\\d*,*\\d*,*\\d원\\s+(.+\\s*.+)\\s+잔액");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("신협" + "(" + mName.group(1).replaceAll("-", "").replaceAll(" ", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("경남")) )
		{
			/*
			 * 경남 11/23 05:01 516210xxx810 입금 경남 비씨/779\41,370       잔액359,685
				경남 11/26 09:02 516210xxx810 입금 경남 신한0069\180,420      잔액1,126,445
			 */
			Pattern pName = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.{12})\\s+입금");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("(\\d*,*\\d*,*\\d*,*\\d)\\s+잔액");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("입금\\s+경남\\s+(.+)\\\\d*,*\\d*,*\\d*,*\\d");
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("경남" + "(" + mName.group(1).replaceAll("-", "").replaceAll(" ", "") + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1((mMemo.group(1)));
					data.setMemo2((mMemo.group(1)));
					data.setMemo3((mMemo.group(1)));
					data.setMemo4((mMemo.group(1)));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("MG체크카드") ) )
		{
			/*
			 * [포인트지급]MG체크카드(5*3*) 안예린님 154원 MG포인트체크 포인트지급
			 */
			
			/*
			 * 이건 등록이 된 문자입니다.
				[MG체크카드(6*2*) 선*훈님 30,000원승인(계좌잔액384,590원)07/27.17:58 고구려삼계탕 ]
				이건 등록이 안된 문자입니다. 
				[MG체크카드(6*2*) 선*훈님 1,400원승인(계좌잔액343,440원)07/30.07:59 비지에프리테일921구] 
			 * 
			 */
			
			Pattern pName = Pattern.compile("\\((\\d\\*\\d\\*)\\)");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("[^\\W]님\\s+(\\d*,*\\d*,*\\d*,*\\d)원");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile("\\d{1,2}:\\d{1,2}\\s+(.+$)");
//				Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("MG체크카드" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//				if (mMemo.find()) 
//				{
//					for (int i=0; i<mMemo.groupCount(); i++) 
//					{
					data.setMemo1("MG포인트체크 포인트지급");
					data.setMemo2("MG포인트체크 포인트지급");
					data.setMemo3("MG포인트체크 포인트지급");
					data.setMemo4("MG포인트체크 포인트지급");
//					}
//				}
//				else
//				{
//					available = false;
//					return;
//				}
			
			available = true;
		}
		else if ( (data.getName().equalsIgnoreCase("미래에셋")) )
		{
			/*
			 * [미래에셋]
				00199****36
				출금액
				30,000
				출금가능금액
				1,000,000
			 */
			Pattern pName = Pattern.compile("(\\d{1,5}\\*{1,5}\\d{1,5})");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금액\\s+(\\d*,*\\d*,*\\d*,*\\d)");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("(\\d{1,2}/\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
//				Pattern pMemo = Pattern.compile("\\s+\\d*,*\\d*,*\\d*,*\\d원\\s+(.+$)");
//				Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName("미래에셋" + "(" + mName.group(1) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("/", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
//				if (mMemo.find()) 
//				{
//					for (int i=0; i<mMemo.groupCount(); i++) 
//					{
					data.setMemo1("내용 없음");
					data.setMemo2("내용 없음");
					data.setMemo3("내용 없음");
					data.setMemo4("내용 없음");
//					}
//				}
//				else
//				{
//					available = false;
//					return;
//				}
			
			available = true;
		}
		else if ( (data.getName().indexOf("제주은행") != -1) )
		{
			/*
			 * 제주은행 07*227 13-02-26(18:23) 지급  32,620   잔액  95,269    #01046911686SKT
			 */
			Pattern pName = Pattern.compile("제주은행\\s+(.{5,8})\\s+");
			Matcher mName = pName.matcher(message);
			Pattern pMoney = Pattern.compile("입금\\s+(\\d*,*\\d*,*\\d*,*\\d)\\s+");
			Matcher mMoney = pMoney.matcher(message);
			Pattern pDate = Pattern.compile("\\d{1,2}-(\\d{1,2}-\\d{1,2})");
			Matcher mDate = pDate.matcher(message);
			Pattern pMemo = Pattern.compile("잔액\\s+-*\\d*,*\\d*,*\\d*,*\\d\\s+(.+$)");	
			Matcher mMemo = pMemo.matcher(message);
			
			if (mName.find())
			{
				for (int i=0; i<mName.groupCount(); i++) 
				{
					data.setName(data.getName() + "(" + (mName.group(1)) + ")");
				}
			}
			else
			{
				available = false;
				return;
			}
			
			if (mMoney.find()) 
			{
				for (int i=0; i<mMoney.groupCount(); i++) 
				{
					data.setMoney((mMoney.group(1).replaceAll(",", "")));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			Calendar calendar = Calendar.getInstance();
			if (date != null && date.length() > 0)
			{
				data.setDate(date);
			} 
			else if (mDate.find()) 
			{
				for (int i=0; i<mDate.groupCount(); i++) 
				{
					data.setDate(calendar.get(Calendar.YEAR)+(mDate.group(1).replaceAll("-", "")));
				}
			}
			else
			{
				data.setDate(BDUtil.getDateDB(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1, calendar.get(Calendar.DAY_OF_MONTH)));
			}
			
			if (mMemo.find()) 
			{
				for (int i=0; i<mMemo.groupCount(); i++) 
				{
					data.setMemo1(mMemo.group(1));
					data.setMemo2(mMemo.group(1));
					data.setMemo3(mMemo.group(1));
					data.setMemo4(mMemo.group(1));
				}
			}
			else
			{
				available = false;
				return;
			}
			
			available = true;
		}
		
		
		if (data.getName() == null || data.getName().equalsIgnoreCase(""))
		{
			SmsInMoney3 sim3 = new SmsInMoney3(data, message, date, smsType, checkcreditFlag);
			this.data = sim3.getData();
			this.smsType = sim3.getSmsType();
			this.available = sim3.getAvailable();
		}
		if (data.getDate() == null || data.getDate().equalsIgnoreCase(""))
		{
			SmsInMoney3 sim3 = new SmsInMoney3(data, message, date, smsType, checkcreditFlag);
			this.data = sim3.getData();
			this.smsType = sim3.getSmsType();
			this.available = sim3.getAvailable();
		}
		if (data.getMoney() == null || data.getMoney().equalsIgnoreCase(""))
		{
			SmsInMoney3 sim3 = new SmsInMoney3(data, message, date, smsType, checkcreditFlag);
			this.data = sim3.getData();
			this.smsType = sim3.getSmsType();
			this.available = sim3.getAvailable();
		}
		if ( (data.getMemo1() == null) || (data.getMemo1().equalsIgnoreCase("")) 
				&& ( (data.getMemo2() == null) || (data.getMemo2().equalsIgnoreCase("")) )
				&& ( (data.getMemo3() == null) || (data.getMemo3().equalsIgnoreCase("")) )
				&& ( (data.getMemo4() == null) || (data.getMemo4().equalsIgnoreCase("")) ) )
		{
			SmsInMoney3 sim3 = new SmsInMoney3(data, message, date, smsType, checkcreditFlag);
			this.data = sim3.getData();
			this.smsType = sim3.getSmsType();
			this.available = sim3.getAvailable();
		}
		if (data.getName() == null || data.getName().equalsIgnoreCase("") 
				|| data.getDate() == null || data.getDate().equalsIgnoreCase("") 
				|| data.getMoney() == null || data.getMoney().equalsIgnoreCase("")
				|| ( data.getMemo1() == null || data.getMemo1().equalsIgnoreCase("") 
				&& data.getMemo2() == null || data.getMemo2().equalsIgnoreCase("")
				&& data.getMemo3() == null || data.getMemo3().equalsIgnoreCase("")
				&& data.getMemo4() == null || data.getMemo4().equalsIgnoreCase("") ) )
		{
			this.available = false;
			return;
		}
	}
		


}
